package com.yuanfengPlus.basicInfoManage.svipinfo.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yuanfengPlus.basicInfoManage.svipinfo.dao.IMemberinfoDao;
import com.yuanfengPlus.basicInfoManage.svipinfo.model.MemberDTO;
import com.yuanfengPlus.basicInfoManage.svipinfo.model.Memberinfo;
import com.yuanfengPlus.basicInfoManage.svipinfo.service.IMemberinfoService;
import com.yuanfengPlus.utils.PageResult;
import com.yuanfengPlus.utils.Result;
import com.yuanfengPlus.utils.SnowflakeIdWorker;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class MenmberinfoImpl implements IMemberinfoService {
    @Resource
    private IMemberinfoDao imbi;
    @Override
    public Result<PageResult> selectMemberAll(MemberDTO memberDTO) {
        PageHelper.startPage(memberDTO.getPage(), memberDTO.getPageSize());
        Page<Memberinfo> memberships = imbi.selectMemberAll(memberDTO);
        return Result.success(new PageResult(memberships.getTotal(), memberships.getResult()));
    }

    @Override
    public Result<String> addMember(Memberinfo memberinfo) {
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(1);
        memberinfo.setMember_id(idWorker.nextId());
        memberinfo.setMember_time(new java.sql.Date(System.currentTimeMillis()));
        memberinfo.setMember_amendtime(new java.sql.Date(System.currentTimeMillis()));
        memberinfo.setMember_state(1);

        int i = imbi.addMember(memberinfo);
        if (i > 0)
            return Result.success("添加成功");
        return Result.failure(400,"添加失败");
    }

    @Override
    public Result<String> updateMember(Memberinfo memberinfo) {
        Integer integer = imbi.updateMember(memberinfo);
        if (integer > 0)
            return Result.success("修改成功");
        return Result.failure(400,"修改失败");
    }

    @Override
    public Result<Memberinfo> selectMember(String id) {
        Memberinfo memberinfo = imbi.selectMember(id);
        if (memberinfo != null)
            return Result.success(memberinfo);
        return Result.failure(400,"没找到");
    }
}
